﻿using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.Domain.Interface;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IntelligentAgriculture.Domain.Impl
{
    public class PermissionRepository : IPermissionRepository
    {
        private readonly AgricultureDbContext _dbContext;
        public PermissionRepository(AgricultureDbContext dbContext)
        {
            _dbContext = dbContext;
        }
        /// <summary>
        /// 获取所有菜单
        /// </summary>
        /// <returns></returns>
        public List<Permission> GetPermission(int pid)
        {
            var list = _dbContext.Permissions.Where(p => p.Pid == pid).ToList();
            return list;
        }
        /// <summary>
        /// 获取角色的权限
        /// </summary>
        /// <param name="roleId">角色Id</param>
        /// <returns></returns>
        public async Task<List<Role>> GetRolePermission(int roleId)
        {
            var roles = await _dbContext.Roles.Where(p => p.Rid == roleId).ToListAsync();
            return roles;
        }
    }
}
